home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
ulib
/
gethexc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
1KB
|
61 lines
/***********************************************************************
* $Id: gethexc.c,v 0.51 1993/07/23 22:00:37 zhao Exp $
*
*. Copyright(c) 1993 by T.C. Zhao
* All rights reserved.
*.
* Read a hex integer. Assuming a-f, A-F, 0-9 is continuous
***********************************************************************/
#if !defined(lint) && defined(F_ID)
char *id_ghex = "$Id: gethexc.c,v 0.51 1993/07/23 22:00:37 zhao Exp $";
#endif
#include <stdio.h>
#include <ctype.h>
#include "ulib.h"
#define IS_FS(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c)==',')
#define IS_COMMENT(c) ((c) == '#')
int
gethexint(FILE * fp)
{
static short hextab[256];
register int num = 0, i, c;
/* initialize the hex table */
if (!hextab['1'])
{
for (i = '1'; i <= '9'; i++)
hextab[i] = i - '0';
for (i = 'A'; i <= 'F'; i++)
hextab[i] = 10 + i - 'A';
for (i = 'a'; i <= 'f'; i++)
hextab[i] = 10 + i - 'a';
}
do {
c = getc(fp);
if (IS_COMMENT(c)) c = skip_comment(fp);
} while (IS_FS(c));
/*
* demand 0[xX]
*/
if (c != '0' || ((c = getc(fp)) != 'x' && c != 'X'))
{
bad_character(c);
return EOF;
}
/*
* now do the coversion
*/
do {
c = getc(fp);
num = (num << 4) + hextab[c];
} while (isxdigit(c));
return num;
}